<!DOCTYPE html>


<html lang="zn-CH">


<head>
  <meta charset="utf-8" />
    
  <meta name="description" content="What I can do is to Do My Personal Best!" />
  
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1" />
  <title>
    vue 开发规范 |  小熊的博客
  </title>
  <meta name="generator" content="hexo-theme-yilia-plus">
  
  <link rel="shortcut icon" href="http://www.cdn.adingxiong.com/b5363a06dc744d79a94021492bcefe27" />
  
  
<link rel="stylesheet" href="/blog/dist/main.css">

  
<link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/Shen-Yu/cdn/css/remixicon.min.css">

  
<link rel="stylesheet" href="/blog/css/custom.css">

  
  
<script src="https://cdn.jsdelivr.net/npm/pace-js@1.0.2/pace.min.js"></script>

  
  

  

<link rel="alternate" href="/blog/atom.xml" title="小熊的博客" type="application/atom+xml">
</head>

</html>

<body>
  <div id="app">
    <main class="content on">
      <section class="outer">
  <article id="post-vue-standard" class="article article-type-post" itemscope
  itemprop="blogPost" data-scroll-reveal>

  <div class="article-inner">
    
    <header class="article-header">
       
<h1 class="article-title sea-center" style="border-left:0" itemprop="name">
  vue 开发规范
</h1>
 

    </header>
    

    
    <div class="article-meta">
      <a href="/blog/2018/12/25/vue-standard/" class="article-date">
  <time datetime="2018-12-24T16:00:00.000Z" itemprop="datePublished">2018-12-25</time>
</a>
      
  <div class="article-category">
    <a class="article-category-link" href="/blog/categories/%E5%9F%BA%E6%9C%AC%E8%A7%84%E8%8C%83/">基本规范</a>
  </div>

      
      
<div class="word_count">
    <span class="post-time">
        <span class="post-meta-item-icon">
            <i class="ri-quill-pen-line"></i>
            <span class="post-meta-item-text"> Word count:</span>
            <span class="post-count">2.2k</span>
        </span>
    </span>

    <span class="post-time">
        &nbsp; | &nbsp;
        <span class="post-meta-item-icon">
            <i class="ri-book-open-line"></i>
            <span class="post-meta-item-text"> Reading time≈</span>
            <span class="post-count">9 min</span>
        </span>
    </span>
</div>

      
    </div>
    

    
    
    <div class="tocbot"></div>





    

    
    <div class="article-entry" itemprop="articleBody">
      
      

      
      <h3 id="组件命名规范"><a href="#组件命名规范" class="headerlink" title="组件命名规范:"></a>组件命名规范:</h3><p>组件名为多个单词，并且用连接线（-）连接，避免与 HTML 标签冲突，并且结构更加清晰。</p>
<p>示例：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line">&#x2F;&#x2F; bad</span><br><span class="line">export default &#123;</span><br><span class="line">    name: &#39;item&#39;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">&#x2F;&#x2F; good</span><br><span class="line">export default &#123;</span><br><span class="line">    name: &#39;page-article-item&#39;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h3 id="vue单文件放置顺序"><a href="#vue单文件放置顺序" class="headerlink" title="vue单文件放置顺序"></a>vue单文件放置顺序</h3><p>单文件组件应该总是让<code>&lt;script&gt;</code>、<code>&lt;template&gt;</code> 和 <code>&lt;style&gt;</code> 标签的顺序保持一致。且 <code>&lt;style&gt;</code> 要放在最后，因为另外两个标签至少要有一个。</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">&lt;!-- ComponentA.vue --&gt;</span><br><span class="line"></span><br><span class="line">&lt;template&gt;...&lt;&#x2F;template&gt;</span><br><span class="line"></span><br><span class="line">&lt;script&gt;&#x2F;* ... *&#x2F;&lt;&#x2F;script&gt;</span><br><span class="line"></span><br><span class="line">&lt;style&gt;&#x2F;* ... *&#x2F;&lt;&#x2F;style&gt;</span><br></pre></td></tr></table></figure>


<h3 id="vue方法放置顺序"><a href="#vue方法放置顺序" class="headerlink" title="vue方法放置顺序"></a>vue方法放置顺序</h3><ol>
<li><p>components    </p>
</li>
<li><p>props        </p>
</li>
<li><p>data         </p>
</li>
<li><p>created       </p>
</li>
<li><p>mounted    </p>
</li>
<li><p>methods</p>
</li>
<li><p>filter</p>
</li>
<li><p>computed</p>
</li>
<li><p>watch</p>
</li>
</ol>
<h3 id="引入组件components规范"><a href="#引入组件components规范" class="headerlink" title="引入组件components规范"></a>引入组件components规范</h3><p>在本组件中需要引入其他vue组件那么</p>
<ol>
<li>首先使用import 引入组件</li>
<li>在components中引入组件</li>
</ol>
<p>例如:</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line">import part1 from &#39;.&#x2F;part&#x2F;part1.vue&#39;;</span><br><span class="line">import part2 from &#39;.&#x2F;part&#x2F;part2.vue&#39;;</span><br><span class="line">import part3 from &#39;.&#x2F;part&#x2F;part3.vue&#39;;</span><br><span class="line"></span><br><span class="line">export default &#123;</span><br><span class="line">  name:&quot;app&quot;,</span><br><span class="line">  components:&#123;part1,part2,part3&#125;,</span><br><span class="line">  data()&#123;</span><br><span class="line">    return &#123;</span><br><span class="line"></span><br><span class="line">    &#125;</span><br><span class="line">  &#125;</span><br><span class="line"></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>


<h3 id="props规范"><a href="#props规范" class="headerlink" title="props规范"></a>props规范</h3><ol>
<li><p>定义 Prop 的时候应该始终以驼峰格式命名,例如:</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><span class="line">&#x2F;&#x2F;bad &#x2F;&#x2F;报错</span><br><span class="line">    props: &#123;</span><br><span class="line">      user-name: &#123;</span><br><span class="line">        type:String,</span><br><span class="line">        default:&#39;张三&#39;</span><br><span class="line">      &#125;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">&#x2F;&#x2F;good</span><br><span class="line">    props: &#123;</span><br><span class="line">      userName: &#123;</span><br><span class="line">        type:String,</span><br><span class="line">        default:&#39;张三&#39;</span><br><span class="line">      &#125;</span><br><span class="line">    &#125;</span><br></pre></td></tr></table></figure>
</li>
<li><p>Prop 的定义应该尽量详细的指定其类型、默认值和验证,例如:</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line">&#x2F;&#x2F;bad</span><br><span class="line"> props:[&#39;userName&#39;,&#39;userSex&#39;]</span><br><span class="line"> </span><br><span class="line">&#x2F;&#x2F;good</span><br><span class="line"> props: &#123;</span><br><span class="line">  userName: &#123;</span><br><span class="line">    type:String,</span><br><span class="line">    default:&#39;张三&#39;</span><br><span class="line">  &#125;,</span><br><span class="line">  userSex:&#123;</span><br><span class="line">    type:Boolean</span><br><span class="line">  &#125;</span><br><span class="line"> &#125;</span><br></pre></td></tr></table></figure>

</li>
</ol>
<h3 id="data书写规范"><a href="#data书写规范" class="headerlink" title="data书写规范"></a>data书写规范</h3><ol>
<li><p>组件的 data 必须是一个函数。当在组件中使用 data 属性的时候 (除了 new Vue 外的任何地方)，它的值必须是返回一个对象的函数。</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><span class="line">   &#x2F;&#x2F;在.vue文件中,必须是一个函数,并且必须返回一个对象 </span><br><span class="line">export default &#123;	</span><br><span class="line"> data () &#123;	</span><br><span class="line">	 return &#123;		</span><br><span class="line">	 foo: &#39;bar&#39;		</span><br><span class="line">	 &#125;	</span><br><span class="line"> &#125;	</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">&#x2F;&#x2F; 在一个 Vue 的根实例上直接使用对象是可以的，	</span><br><span class="line">&#x2F;&#x2F; 因为只存在一个这样的实例。	</span><br><span class="line">new Vue(&#123;	</span><br><span class="line"> data: &#123;	</span><br><span class="line"> foo: &#39;bar&#39;	</span><br><span class="line"> &#125;	</span><br><span class="line">&#125;)</span><br></pre></td></tr></table></figure></li>
<li><p>所有初始化数据放在data(或者created)中处理 然后返回,不能放在在模块外面.例如:</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br></pre></td><td class="code"><pre><span class="line">   &#x2F;&#x2F;bad  </span><br><span class="line">    var  name&#x3D;&#39;张三&#39;</span><br><span class="line"> export default &#123;</span><br><span class="line">   name: &quot;project-module-one-part1&quot;,</span><br><span class="line">   props:&#123;</span><br><span class="line">     num:&#123;</span><br><span class="line">        type:Number</span><br><span class="line">     &#125;</span><br><span class="line">   &#125;,</span><br><span class="line">   data()&#123;</span><br><span class="line">     return&#123;</span><br><span class="line">       name</span><br><span class="line">     &#125;</span><br><span class="line">   &#125;</span><br><span class="line"> &#125;</span><br><span class="line"></span><br><span class="line">  &#x2F;&#x2F;good </span><br><span class="line">  export default &#123;</span><br><span class="line">   name: &quot;project-module-one-part1&quot;,</span><br><span class="line">   props:&#123;</span><br><span class="line">     num:&#123;</span><br><span class="line">        type:Number</span><br><span class="line">     &#125;</span><br><span class="line">   &#125;,</span><br><span class="line">   data()&#123;</span><br><span class="line">     &#x2F;&#x2F;数据处理都在data中</span><br><span class="line">     let name&#x3D;&#39;张三&#39;</span><br><span class="line">     return&#123;</span><br><span class="line">       name</span><br><span class="line">     &#125;</span><br><span class="line">   &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure></li>
<li><p>data中主要实现数据初始化以及表单校验.</p>
</li>
</ol>
<h3 id="created-方法规范"><a href="#created-方法规范" class="headerlink" title="created 方法规范"></a>created 方法规范</h3><p>created方法中,el并没有被初始化完成,而data已经被创建,这里可以进行一些数据处理</p>
<ol>
<li>部分访问权限验证</li>
<li>页面级插件数据初始化</li>
<li>页面默认数据加载,数据初始化</li>
</ol>
<h3 id="methods方法规范"><a href="#methods方法规范" class="headerlink" title="methods方法规范"></a>methods方法规范</h3><ul>
<li>命名规范<ol>
<li>事件方法以on开头,例如(onNameChange,onUserClick)</li>
<li>使用驼峰命名</li>
<li>词意明确,见词知意</li>
</ol>
</li>
<li>函数中统一使用_self=this来解决this的全局指向问题</li>
</ul>
<h3 id="部分写作规范"><a href="#部分写作规范" class="headerlink" title="部分写作规范"></a>部分写作规范</h3><ol>
<li><p><code>v-for</code> 必须设置<code>key</code>, 在组件上_总是_必须用 <code>key</code> 配合<code>v-for</code>，以便维护内部组件及其子树的状态,甚至在元素上维护可预测的行为.</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><span class="line">   &#x2F;&#x2F;bad</span><br><span class="line">&lt;ul&gt;	</span><br><span class="line"> &lt;li v-for&#x3D;&quot;todo in todos&quot;&gt;	</span><br><span class="line"> &#123;&#123; todo.text &#125;&#125;	</span><br><span class="line"> &lt;&#x2F;li&gt;	</span><br><span class="line">&lt;&#x2F;ul&gt;</span><br><span class="line"></span><br><span class="line">   &#x2F;&#x2F;good</span><br><span class="line">&lt;ul&gt;	</span><br><span class="line"> &lt;li	</span><br><span class="line"> v-for&#x3D;&quot;todo in todos&quot;	</span><br><span class="line"> :key&#x3D;&quot;todo.id&quot;	</span><br><span class="line"> &gt;	</span><br><span class="line"> &#123;&#123; todo.text &#125;&#125;	</span><br><span class="line"> &lt;&#x2F;li&gt;	</span><br><span class="line">&lt;&#x2F;ul&gt;</span><br></pre></td></tr></table></figure>
</li>
<li><p>v-for 应该避免与 v-if 在同一个元素（例如：<code>&lt;li&gt;</code>）上使用，因为 v-for 的优先级比 v-if 更高，为了避免无效计算和渲染，应该尽量将 v-if 放到容器的父元素之上。例如:</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line"> &#x2F;&#x2F; bad</span><br><span class="line">&lt;ul&gt;</span><br><span class="line">    &lt;li v-for&#x3D;&quot;item in list&quot; :key&#x3D;&quot;item.id&quot; v-if&#x3D;&quot;showList&quot;&gt;</span><br><span class="line">        &#123;&#123; item.title &#125;&#125;</span><br><span class="line">    &lt;&#x2F;li&gt;</span><br><span class="line">&lt;&#x2F;ul&gt;	</span><br><span class="line">&#x2F;&#x2F; good</span><br><span class="line">&lt;ul v-if&#x3D;&quot;showList&quot;&gt;</span><br><span class="line">    &lt;li v-for&#x3D;&quot;item in list&quot; :key&#x3D;&quot;item.id&quot;&gt;</span><br><span class="line">        &#123;&#123; item.title &#125;&#125;</span><br><span class="line">    &lt;&#x2F;li&gt;</span><br><span class="line">&lt;&#x2F;ul&gt;</span><br></pre></td></tr></table></figure></li>
<li><p>v-if / v-else-if / v-else<br>若同一组 v-if 逻辑控制中的元素逻辑相同，Vue 为了更高效的元素切换，会复用相同的部分，例如：value。为了避免复用带来的不合理效果，应该在同种元素上加上 key 做标识。</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><span class="line">   &#x2F;&#x2F; bad</span><br><span class="line">&lt;div v-if&#x3D;&quot;hasData&quot;&gt;</span><br><span class="line">    &lt;span&gt;&#123;&#123; mazeyData &#125;&#125;&lt;&#x2F;span&gt;</span><br><span class="line">&lt;&#x2F;div&gt;</span><br><span class="line">&lt;div v-else&gt;</span><br><span class="line">    &lt;span&gt;无数据&lt;&#x2F;span&gt;</span><br><span class="line">&lt;&#x2F;div&gt;</span><br><span class="line"></span><br><span class="line">&#x2F;&#x2F; good</span><br><span class="line">&lt;div v-if&#x3D;&quot;hasData&quot; key&#x3D;&quot;mazey-data&quot;&gt;</span><br><span class="line">    &lt;span&gt;&#123;&#123; mazeyData &#125;&#125;&lt;&#x2F;span&gt;</span><br><span class="line">&lt;&#x2F;div&gt;</span><br><span class="line">&lt;div v-else key&#x3D;&quot;mazey-none&quot;&gt;</span><br><span class="line">    &lt;span&gt;无数据&lt;&#x2F;span&gt;</span><br><span class="line">&lt;&#x2F;div&gt;</span><br></pre></td></tr></table></figure>
</li>
<li><p>模板中的表达式应该是简单的<br>组件模板应该只包含简单的表达式，复杂的表达式则应该重构为计算属性或方法。<br>复杂表达式会让你的模板变得不那么声明式。我们应该尽量描述应该出现的是什么，而非如何计算那个值。而且计算属性和方法使得代码可以重用。</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br></pre></td><td class="code"><pre><span class="line"> &#x2F;&#x2F;bad</span><br><span class="line"> &lt;span&gt;</span><br><span class="line">&#123;&#123;</span><br><span class="line"></span><br><span class="line"> fullName.split(&#39; &#39;).map(function (word) &#123;</span><br><span class="line"></span><br><span class="line"> return word[0].toUpperCase() + word.slice(1)</span><br><span class="line"></span><br><span class="line"> &#125;).join(&#39; &#39;)</span><br><span class="line"></span><br><span class="line">&#125;&#125;</span><br><span class="line"> &lt;&#x2F;span&gt;</span><br><span class="line"></span><br><span class="line">  &#x2F;&#x2F;good</span><br><span class="line">&lt;!-- 在模板中 --&gt;</span><br><span class="line"></span><br><span class="line">&lt;span&gt;&#123;&#123; normalizedFullName &#125;&#125;&lt;&#x2F;span&gt;</span><br><span class="line"></span><br><span class="line">&#x2F;&#x2F; 复杂表达式已经移入一个计算属性</span><br><span class="line"></span><br><span class="line">computed: &#123;</span><br><span class="line"></span><br><span class="line"> normalizedFullName: function () &#123;</span><br><span class="line"></span><br><span class="line"> return this.fullName.split(&#39; &#39;).map(function (word) &#123;</span><br><span class="line"></span><br><span class="line"> return word[0].toUpperCase() + word.slice(1)</span><br><span class="line"></span><br><span class="line"> &#125;).join(&#39; &#39;)</span><br><span class="line"></span><br><span class="line"> &#125;</span><br><span class="line"></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure></li>
<li><p>页面初始化需要的数据请求，一般在 <code>created</code>（或<code>beforeRouter</code>） 里面进行请求，如果涉及到需要页面加载完成之后的话就用 <code>mounted</code>。</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br></pre></td><td class="code"><pre><span class="line">  export default &#123;</span><br><span class="line">    data() &#123;</span><br><span class="line">        return &#123;</span><br><span class="line">        </span><br><span class="line">        &#125;</span><br><span class="line">    &#125;,</span><br><span class="line">    created()&#123;</span><br><span class="line">       &#x2F;&#x2F;在created的时候，视图中的html并没有渲染出来，所以此时如果直接去操作html的dom节点，一定找不到相关的元素</span><br><span class="line">       &#x2F;&#x2F;有 data 无el</span><br><span class="line">       this.getData()</span><br><span class="line">    &#125;,</span><br><span class="line">    mounted() &#123;</span><br><span class="line">        &#x2F;&#x2F;在mounted中，由于此时html已经渲染出来了，所以可以直接操作dom节点，（此时document.getelementById 即可生效了）。</span><br><span class="line">        this.getData()</span><br><span class="line">    &#125;,</span><br><span class="line">    methods: &#123;</span><br><span class="line">        getData() &#123;</span><br><span class="line">            &#x2F;&#x2F; 请求数据</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;,</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
</li>
<li><p>带引号的特性值</p>
</li>
</ol>
<p>非空 HTML 特性值应该始终带引号 (单引号或双引号，选你 JS 里不用的那个)。</p>
<p>在 HTML 中不带空格的特性值是可以没有引号的，但这样做常常导致带空格的特征值被回避，导致其可读性变差。</p>
   <figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">&#x2F;&#x2F;bad &#x2F;&#x2F;报错</span><br><span class="line">&lt;button :style&#x3D;&#123;width:sidebarWidth+&#39;px&#39;&#125;&gt;&lt;&#x2F;button&gt;</span><br><span class="line"></span><br><span class="line">&#x2F;&#x2F;good</span><br><span class="line">&lt;button :style&#x3D;&quot;&#123; width: sidebarWidth + &#39;px&#39; &#125;&quot;&gt;&lt;&#x2F;button&gt;</span><br></pre></td></tr></table></figure>
<ol start="7">
<li>指令缩写</li>
</ol>
<p>使用指令缩写 (用 <code>:</code> 表示 <code>v-bind:</code> 和用 <code>@</code> 表示 <code>v-on:</code>)</p>
   <figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><span class="line">   &#x2F;&#x2F;bad</span><br><span class="line">&lt;input</span><br><span class="line"></span><br><span class="line"> v-bind:value&#x3D;&quot;newTodoText&quot;</span><br><span class="line"></span><br><span class="line"> :placeholder&#x3D;&quot;newTodoInstructions&quot;</span><br><span class="line"></span><br><span class="line">&gt;</span><br><span class="line">   &#x2F;&#x2F;good</span><br><span class="line">   &lt;input</span><br><span class="line"></span><br><span class="line"> @input&#x3D;&quot;onInput&quot;</span><br><span class="line"></span><br><span class="line"> @focus&#x3D;&quot;onFocus&quot;</span><br><span class="line"></span><br><span class="line">&gt;</span><br></pre></td></tr></table></figure>

<h3 id="注释规范"><a href="#注释规范" class="headerlink" title="注释规范"></a>注释规范</h3><h4 id="js注释"><a href="#js注释" class="headerlink" title="js注释"></a>js注释</h4><p>代码注释在一个项目的后期维护中显的尤为重要，所以我们要为每一个被复用的组件编写组件使用说明，为组件中每一个方法编写方法说明。<br>以下情况，务必添加注释</p>
<ol>
<li><p>公共组件使用说明</p>
</li>
<li><p>各组件中重要函数或者类说明</p>
</li>
<li><p>复杂的业务逻辑处理说明</p>
</li>
<li><p>特殊情况的代码处理说明,对于代码中特殊用途的变量等需要进行注释描述</p>
</li>
<li><p>注释块必须以/<strong>（至少两个星号）开头</strong>/；</p>
</li>
<li><p>单行注释使用//；</p>
<ul>
<li>单行注释<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">普通方法一般使用单行注释&#x2F;&#x2F; 来说明该方法主要作用</span><br></pre></td></tr></table></figure></li>
<li>多行注释<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line">组件使用说明，和调用说明 </span><br><span class="line">&lt;!--公用组件：数据表格</span><br><span class="line">   &#x2F;**</span><br><span class="line">   * 组件名称</span><br><span class="line">   * @module 组件存放位置</span><br><span class="line">   * @desc 组件描述</span><br><span class="line">   * @author 组件作者</span><br><span class="line">   * @date 2017年12月05日17:22:43</span><br><span class="line">   * @param &#123;Object&#125; [title]    - 参数说明</span><br><span class="line">   * @param &#123;String&#125; [columns] - 参数说明</span><br><span class="line">   * @example 调用示例</span><br><span class="line">   *  &lt;hbTable :title&#x3D;&quot;title&quot; :columns&#x3D;&quot;columns&quot; :tableData&#x3D;&quot;tableData&quot;&gt;&lt;&#x2F;hbTable&gt;</span><br><span class="line">       *&#x2F;</span><br><span class="line">    --&gt;</span><br></pre></td></tr></table></figure>

</li>
</ul>
</li>
</ol>
<h4 id="scss注释"><a href="#scss注释" class="headerlink" title="scss注释"></a>scss注释</h4><p>scss 支持两种注释</p>
<ul>
<li><p>多行注释 - 这些使用 /<em>和</em>/ 写入。多行注释都保留在CSS输出。</p>
</li>
<li><p>单行注释 - 这些是使用//跟着注释。单行注释不会保留在CSS输出。</p>
  <figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line">&#x2F;* 这是</span><br><span class="line"> * 多行注释</span><br><span class="line"> * 多行注释</span><br><span class="line"> * 会在编译好的css中保留输出. *&#x2F;</span><br><span class="line">body &#123; color: black; &#125;</span><br><span class="line"></span><br><span class="line">&#x2F;&#x2F; 这是单行注释</span><br><span class="line">&#x2F;&#x2F; 单行注释不会在css中保留输出</span><br><span class="line">a &#123; color: blue; &#125;</span><br></pre></td></tr></table></figure></li>
</ul>

      
      <!-- reward -->
      
      <div id="reward-btn">
        Donate
      </div>
      
    </div>
    
    
      <!-- copyright -->
      
        <div class="declare">
          <ul class="post-copyright">
            <li>
              <i class="ri-copyright-line"></i>
              <strong>Copyright： </strong>
              Copyright is owned by the author. For commercial reprints, please contact the author for authorization. For non-commercial reprints, please indicate the source.
            </li>
          </ul>
        </div>
        
    <footer class="article-footer">
      
          
<div class="share-btn">
      <span class="share-sns share-outer">
        <i class="ri-share-forward-line"></i>
        分享
      </span>
      <div class="share-wrap">
        <i class="arrow"></i>
        <div class="share-icons">
          
          <a class="weibo share-sns" href="javascript:;" data-type="weibo">
            <i class="ri-weibo-fill"></i>
          </a>
          <a class="weixin share-sns wxFab" href="javascript:;" data-type="weixin">
            <i class="ri-wechat-fill"></i>
          </a>
          <a class="qq share-sns" href="javascript:;" data-type="qq">
            <i class="ri-qq-fill"></i>
          </a>
          <a class="douban share-sns" href="javascript:;" data-type="douban">
            <i class="ri-douban-line"></i>
          </a>
          <!-- <a class="qzone share-sns" href="javascript:;" data-type="qzone">
            <i class="icon icon-qzone"></i>
          </a> -->
          
          <a class="facebook share-sns" href="javascript:;" data-type="facebook">
            <i class="ri-facebook-circle-fill"></i>
          </a>
          <a class="twitter share-sns" href="javascript:;" data-type="twitter">
            <i class="ri-twitter-fill"></i>
          </a>
          <a class="google share-sns" href="javascript:;" data-type="google">
            <i class="ri-google-fill"></i>
          </a>
        </div>
      </div>
</div>

<div class="wx-share-modal">
    <a class="modal-close" href="javascript:;"><i class="ri-close-circle-line"></i></a>
    <p>扫一扫，分享到微信</p>
    <div class="wx-qrcode">
      <img src="//api.qrserver.com/v1/create-qr-code/?size=150x150&data=https://bodboy.gitee.io/blog/2018/12/25/vue-standard/" alt="微信分享二维码">
    </div>
</div>

<div id="share-mask"></div>
      
      
  <ul class="article-tag-list" itemprop="keywords"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/blog/tags/Hexo/" rel="tag">Hexo</a></li><li class="article-tag-list-item"><a class="article-tag-list-link" href="/blog/tags/Sample/" rel="tag">Sample</a></li></ul>


    </footer>

  </div>

  
  
  <nav class="article-nav">
    
      <a href="/blog/2019/01/09/IEDA%E4%BD%BF%E7%94%A8%E8%AF%B4%E6%98%8E/" class="article-nav-link">
        <strong class="article-nav-caption">上一篇</strong>
        <div class="article-nav-title">
          
            IEDA+DOCLever操作说明
          
        </div>
      </a>
    
    
      <a href="/blog/2018/12/25/markdown-standard/" class="article-nav-link">
        <strong class="article-nav-caption">下一篇</strong>
        <div class="article-nav-title">Markdown 编写规范</div>
      </a>
    
  </nav>


  

  
  
<!-- valine评论 -->
<div id="vcomments-box">
    <div id="vcomments">
    </div>
</div>
<script src="//cdn1.lncld.net/static/js/3.0.4/av-min.js"></script>
<script src='https://cdn.jsdelivr.net/npm/valine@1.3.10/dist/Valine.min.js'></script>
<script>
    new Valine({
        el: '#vcomments',
        app_id: 'uW8QYGvvhWmNWdiwpznJ0GVa-gzGzoHsz',
        app_key: 'LrJhMzx9qEwcMV1DJjTI6f6C',
        path: window.location.pathname,
        notify: 'false',
        verify: 'false',
        avatar: '[object Object]',
        placeholder: '给我的文章加点评论吧~',
        recordIP: true
    });
    const infoEle = document.querySelector('#vcomments .info');
    if (infoEle && infoEle.childNodes && infoEle.childNodes.length > 0) {
        infoEle.childNodes.forEach(function (item) {
            item.parentNode.removeChild(item);
        });
    }
</script>
<style>
    #vcomments-box {
        padding: 5px 30px;
    }

    @media screen and (max-width: 800px) {
        #vcomments-box {
            padding: 5px 0px;
        }
    }

    #vcomments-box #vcomments {
        background-color: #fff;
    }

    .v .vlist .vcard .vh {
        padding-right: 20px;
    }

    .v .vlist .vcard {
        padding-left: 10px;
    }
</style>

  

  
  
  
  
  

</article>
</section>
      <footer class="footer">
  <div class="outer">
    <ul>
      <li>
        Copyrights &copy;
        2019-2021
        <i class="ri-heart-fill heart_icon"></i> panda
      </li>
    </ul>
    <ul>
      <li>
        
        
        
        Powered by <a href="https://hexo.io" target="_blank">Hexo</a>
        <span class="division">|</span>
        Theme - <a href="https://github.com/Shen-Yu/hexo-theme-ayer" target="_blank">Ayer</a>
        
      </li>
    </ul>
    <ul>
      <li>
        
        
        <span>
  <span><i class="ri-user-3-fill"></i>Visitors:<span id="busuanzi_value_site_uv"></span></s>
  <span class="division">|</span>
  <span><i class="ri-eye-fill"></i>Views:<span id="busuanzi_value_page_pv"></span></span>
</span>
        
      </li>
    </ul>
    <ul>
      
    </ul>
    <ul>
      <li>
        <!-- cnzz统计 -->
        
        <script type="text/javascript" src='https://s9.cnzz.com/z_stat.php?id=1278069914&amp;web_id=1278069914'></script>
        
      </li>
    </ul>
  </div>
</footer>
      <div class="float_btns">
        <div class="totop" id="totop">
  <i class="ri-arrow-up-line"></i>
</div>

<div class="todark" id="todark">
  <i class="ri-moon-line"></i>
</div>

      </div>
    </main>
    <aside class="sidebar on">
      <button class="navbar-toggle"></button>
<nav class="navbar">
  
  <div class="logo">
    <a href="/blog/"><img src="https://portrait.gitee.com/uploads/avatars/user/1007/3023420_bodboy_1578973210.png!avatar200" alt="小熊的博客"></a>
  </div>
  
  <ul class="nav nav-main">
    
    <li class="nav-item">
      <a class="nav-item-link" href="/blog/">主页</a>
    </li>
    
    <li class="nav-item">
      <a class="nav-item-link" href="/blog/archives">归档</a>
    </li>
    
    <li class="nav-item">
      <a class="nav-item-link" href="/blog/categories">分类</a>
    </li>
    
    <li class="nav-item">
      <a class="nav-item-link" href="/blog/tags">标签</a>
    </li>
    
    <li class="nav-item">
      <a class="nav-item-link" href="/blog/tags/%E6%97%85%E8%A1%8C/">旅行</a>
    </li>
    
    <li class="nav-item">
      <a class="nav-item-link" href="/blog/about">关于我</a>
    </li>
    
  </ul>
</nav>
<nav class="navbar navbar-bottom">
  <ul class="nav">
    <li class="nav-item">
      
      <a class="nav-item-link nav-item-search"  title="Search">
        <i class="ri-search-line"></i>
      </a>
      
      
      <a class="nav-item-link" target="_blank" href="/blog/atom.xml" title="RSS Feed">
        <i class="ri-rss-line"></i>
      </a>
      
    </li>
  </ul>
</nav>
<div class="search-form-wrap">
  <div class="local-search local-search-plugin">
  <input type="search" id="local-search-input" class="local-search-input" placeholder="Search...">
  <div id="local-search-result" class="local-search-result"></div>
</div>
</div>
    </aside>
    <script>
      if (window.matchMedia("(max-width: 768px)").matches) {
        document.querySelector('.content').classList.remove('on');
        document.querySelector('.sidebar').classList.remove('on');
      }
    </script>
    <div id="mask"></div>

<!-- #reward -->
<div id="reward">
  <span class="close"><i class="ri-close-line"></i></span>
  <p class="reward-p"><i class="ri-cup-line"></i>请我喝杯咖啡吧~</p>
  <div class="reward-box">
    
    <div class="reward-item">
      <img class="reward-img" src="/blog/images/alipay.jpg">
      <span class="reward-type">支付宝</span>
    </div>
    
    
    <div class="reward-item">
      <img class="reward-img" src="/blog/images/wechat.jpg">
      <span class="reward-type">微信</span>
    </div>
    
  </div>
</div>
    
<script src="/blog/js/jquery-2.0.3.min.js"></script>


<script src="/blog/js/lazyload.min.js"></script>


<script>
  try {
    var typed = new Typed("#subtitle", {
      strings: ['面朝大海，春暖花开', '愿你一生努力，一生被爱', '想要的都拥有，得不到的都释怀'],
      startDelay: 0,
      typeSpeed: 200,
      loop: true,
      backSpeed: 100,
      showCursor: true
    });
  } catch (err) {
  }

</script>




<script src="/blog/js/tocbot.min.js"></script>

<script>
  // Tocbot_v4.7.0  http://tscanlin.github.io/tocbot/
  tocbot.init({
    tocSelector: '.tocbot',
    contentSelector: '.article-entry',
    headingSelector: 'h1, h2, h3, h4, h5, h6',
    hasInnerContainers: true,
    scrollSmooth: true,
    scrollContainer: 'main',
    positionFixedSelector: '.tocbot',
    positionFixedClass: 'is-position-fixed',
    fixedSidebarOffset: 'auto'
  });
</script>



<script src="https://cdn.jsdelivr.net/npm/jquery-modal@0.9.2/jquery.modal.min.js"></script>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/jquery-modal@0.9.2/jquery.modal.min.css">
<script src="https://cdn.jsdelivr.net/npm/justifiedGallery@3.7.0/dist/js/jquery.justifiedGallery.min.js"></script>

<script src="/blog/dist/main.js"></script>



<!-- Root element of PhotoSwipe. Must have class pswp. -->
<div class="pswp" tabindex="-1" role="dialog" aria-hidden="true">

    <!-- Background of PhotoSwipe. 
         It's a separate element as animating opacity is faster than rgba(). -->
    <div class="pswp__bg"></div>

    <!-- Slides wrapper with overflow:hidden. -->
    <div class="pswp__scroll-wrap">

        <!-- Container that holds slides. 
            PhotoSwipe keeps only 3 of them in the DOM to save memory.
            Don't modify these 3 pswp__item elements, data is added later on. -->
        <div class="pswp__container">
            <div class="pswp__item"></div>
            <div class="pswp__item"></div>
            <div class="pswp__item"></div>
        </div>

        <!-- Default (PhotoSwipeUI_Default) interface on top of sliding area. Can be changed. -->
        <div class="pswp__ui pswp__ui--hidden">

            <div class="pswp__top-bar">

                <!--  Controls are self-explanatory. Order can be changed. -->

                <div class="pswp__counter"></div>

                <button class="pswp__button pswp__button--close" title="Close (Esc)"></button>

                <button class="pswp__button pswp__button--share" style="display:none" title="Share"></button>

                <button class="pswp__button pswp__button--fs" title="Toggle fullscreen"></button>

                <button class="pswp__button pswp__button--zoom" title="Zoom in/out"></button>

                <!-- Preloader demo http://codepen.io/dimsemenov/pen/yyBWoR -->
                <!-- element will get class pswp__preloader--active when preloader is running -->
                <div class="pswp__preloader">
                    <div class="pswp__preloader__icn">
                        <div class="pswp__preloader__cut">
                            <div class="pswp__preloader__donut"></div>
                        </div>
                    </div>
                </div>
            </div>

            <div class="pswp__share-modal pswp__share-modal--hidden pswp__single-tap">
                <div class="pswp__share-tooltip"></div>
            </div>

            <button class="pswp__button pswp__button--arrow--left" title="Previous (arrow left)">
            </button>

            <button class="pswp__button pswp__button--arrow--right" title="Next (arrow right)">
            </button>

            <div class="pswp__caption">
                <div class="pswp__caption__center"></div>
            </div>

        </div>

    </div>

</div>

<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/photoswipe@4.1.3/dist/photoswipe.min.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/photoswipe@4.1.3/dist/default-skin/default-skin.min.css">
<script src="https://cdn.jsdelivr.net/npm/photoswipe@4.1.3/dist/photoswipe.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/photoswipe@4.1.3/dist/photoswipe-ui-default.min.js"></script>

<script>
    function viewer_init() {
        let pswpElement = document.querySelectorAll('.pswp')[0];
        let $imgArr = document.querySelectorAll(('.article-entry img:not(.reward-img)'))

        $imgArr.forEach(($em, i) => {
            $em.onclick = () => {
                // slider展开状态
                // todo: 这样不好，后面改成状态
                if (document.querySelector('.left-col.show')) return
                let items = []
                $imgArr.forEach(($em2, i2) => {
                    let img = $em2.getAttribute('data-idx', i2)
                    let src = $em2.getAttribute('data-target') || $em2.getAttribute('src')
                    let title = $em2.getAttribute('alt')
                    // 获得原图尺寸
                    const image = new Image()
                    image.src = src
                    items.push({
                        src: src,
                        w: image.width || $em2.width,
                        h: image.height || $em2.height,
                        title: title
                    })
                })
                var gallery = new PhotoSwipe(pswpElement, PhotoSwipeUI_Default, items, {
                    index: parseInt(i)
                });
                gallery.init()
            }
        })
    }
    viewer_init()
</script>


<script type="text/x-mathjax-config">
  MathJax.Hub.Config({
      tex2jax: {
          inlineMath: [ ['$','$'], ["\\(","\\)"]  ],
          processEscapes: true,
          skipTags: ['script', 'noscript', 'style', 'textarea', 'pre', 'code']
      }
  });

  MathJax.Hub.Queue(function() {
      var all = MathJax.Hub.getAllJax(), i;
      for(i=0; i < all.length; i += 1) {
          all[i].SourceElement().parentNode.className += ' has-jax';
      }
  });
</script>

<script src="https://cdn.jsdelivr.net/npm/mathjax@2.7.6/unpacked/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>
<script>
  var ayerConfig = {
    mathjax: true
  }
</script>




<script src="/blog/js/busuanzi-2.3.pure.min.js"></script>



<script type="text/javascript" src="https://js.users.51.la/20544303.js"></script>

  
<script src="/blog/js/clickLove.js"></script>



<!-- 复制 -->



    
    <div id="music">
    
    
    
    <iframe frameborder="no" border="1" marginwidth="0" marginheight="0" width="200" height="52"
        src="//music.163.com/outchain/player?type=2&id=1297802566&auto=1&height=32"></iframe>
</div>

<style>
    #music {
        position: fixed;
        right: 15px;
        bottom: 0;
        z-index: 998;
    }
</style>
    
  </div>
</body>

</html>